import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";

// 引入一些插件
import Vue from "@vitejs/plugin-vue";

import VueDevTools from "vite-plugin-vue-devtools"; //vue dev tool
import Autoimport from "unplugin-auto-import/vite"; //自动引入方法
import Components from "unplugin-vue-components/vite"; //自动注册组件
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    Vue(),
    // VueDevTools(),
    Autoimport({
      imports: ["vue", "vue-router", "pinia", "@vueuse/core"],
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      dirs: ["src/components/*"],
      resolvers: [ElementPlusResolver()],
    }),
  ],
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/assets/styles/main.scss" as *;`,
      },
    },
  },
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  server: {
    port: 5678,
    host: "0.0.0.0",
    proxy: {
      "/api": {
        target: "https://zx.swzmt.com/", //目标url
        changeOrigin: true, //支持跨域
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
  build: {
    commonjsOptions: {
      include: [/node_modules/],
    },
  },
  optimizeDeps: {
    include: [
      "@jiaminghi/c-render",
      " @jiaminghi/c-render/lib/plugin/util",
      "@jiaminghi/charts/lib/util/index",
      "@jiaminghi/charts/lib/util",
      "@jiaminghi/charts/lib/extend/index",
      "@jiaminghi/charts",
      "@jiaminghi/color",
    ],
  },
});
